﻿configuration CustomPSModulePath
{
    param ($ServerName)

    Node $ServerName
    {

        Environment CustomPSModulePath
        {
            Name = "PSModulePath"
            Ensure = "Present"
            Path = $true
            Value = "D:\devel\MESF\Main\Powershell\DSCResources"
        }
    }
}

configuration FreeAdminForChildPC
{

    param ($ServerName)

    Node $ServerName
    {
        Registry HideAdministrateur
        {
            Ensure = "Present"  # You can also set Ensure to "Absent"
            Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\Userlist"
            ValueName = "Administrateur"
            ValueData = "0"
            ValueType = "Dword"
            Force = $true
        }
    }
}



configuration CustomPSModulePath
{
    param ($ServerName)

    Node $ServerName
    {

        Environment CustomPSModulePath
        {
            Name = "PSModulePath"
            Ensure = "Present"
            Path = $true
            Value = "D:\devel\MESF\Main\Powershell\CustomPowershellModules"
        }
    }
}

configuration DSCWave 
{
    param ($ServerName)

    Node $ServerName
    {

        Archive DSCWave {
            DependsOn = '[Script]DSCWave'
            Ensure = 'Present'
            #Path = "$env:windirtempDSC Resource Kit Wave 6 08212014.zip";
            Path = "D:\devel\dscoutput\temp\DSC-Resource-Kit-All.zip"
            #Destination = "$env:ProgramFilesWindowsPowerShellModules";
            Destination = "D:\devel\MESF\Main\Powershell\CustomPowershellModules"
        }

        <#
        Script DSCWave {
            GetScript = { @{ Result = (Test-Path -Path "$env:windirtempDSC Resource Kit Wave 6 08212014.zip"); } };
            SetScript = {
                $Uri = 'http://gallery.technet.microsoft.com/DSC-Resource-Kit-All-c449312d/file/124120/1/DSC%20Resource%20Kit%20Wave%206%2008212014.zip';
                $OutFile = "$env:windirtempDSC Resource Kit Wave 6 08212014.zip";
                Invoke-WebRequest -Uri $Uri -OutFile $OutFile;
                Unblock-File -Path $OutFile;
                };
            TestScript = { Test-Path -Path "$env:windirtempDSC Resource Kit Wave 6 08212014.zip"; }
        }
        #>
        Script DSCWave {
            GetScript = { @{ Result = (Test-Path -Path "D:\devel\dscoutput\temp\DSC-Resource-Kit-All.zip"); } };
            SetScript = {
                $Uri = 'https://gallery.technet.microsoft.com/scriptcenter/DSC-Resource-Kit-All-c449312d/file/131371/1/DSC%20Resource%20Kit%20Wave%209%2012172014.zip';
                $OutFile = "D:\devel\dscoutput\temp\DSC-Resource-Kit-All.zip";
                Invoke-WebRequest -Uri $Uri -OutFile $OutFile;
                Unblock-File -Path $OutFile;
                };
            TestScript = { Test-Path -Path "D:\devel\dscoutput\temp\DSC-Resource-Kit-All.zip"; }
        }

    }
}


configuration ManagementTools
{
    param ($ServerName)

    Node $ServerName
    {


        Package Install_SlikSvn {
            DependsOn = '[Script]Download_SlikSvn'
            Ensure = 'Present'
            Name = 'Slik Subversion 1.8.11 (x64)'
            Path = "D:\devel\dscoutput\temp\Slik-Subversion-1.8.11-x64.msi"
            ProductId = 'C215CE2E-8A95-43E7-8FD6-C163CB945BBF'
            Arguments = "/QUIET /NORESTART"                
        }


        Package Install_Winmerge {
            DependsOn = '[Script]Download_WinMerge'
            Ensure = 'Present'
            Name = 'WinMerge 2.14.0'
            Path = "D:\devel\dscoutput\temp\WinMerge-2.14.0-Setup.exe"
            ProductId = ''
            Arguments = "/VERYSILENT /SP- /NORESTART"                
        }

        Script Download_VS2012_TeamExplorer {
            GetScript = { @{ Result = (Test-Path -Path "D:\devel\dscoutput\temp\VS2012_TEAMEXP_MSDN_enu.iso"); } };
            SetScript = {
                $Uri = 'http://download.microsoft.com/download/9/B/4/9B44FFC8-64C2-4091-9028-6E8550E9C96E/VS2012_TEAMEXP_MSDN_enu.iso';
                $OutFile = "D:\devel\dscoutput\temp\VS2012_TEAMEXP_MSDN_enu.iso";
                Invoke-WebRequest -Uri $Uri -OutFile $OutFile;
                Unblock-File -Path $OutFile;
                };
            TestScript = { Test-Path -Path "D:\devel\dscoutput\temp\VS2012_TEAMEXP_MSDN_enu.iso"; }
        }


        Script Download_WinMerge {
            GetScript = { @{ Result = (Test-Path -Path "D:\devel\dscoutput\temp\WinMerge-2.14.0-Setup.exe"); } };
            SetScript = {
                #$Uri = 'http://downloads.sourceforge.net/project/winmerge/stable/2.14.0/WinMerge-2.14.0-Setup.exe?r=&ts=1420383862&use_mirror=switch';
                $Uri = 'http://colocrossing.dl.sourceforge.net/project/winmerge/stable/2.14.0/WinMerge-2.14.0-Setup.exe';
                $OutFile = "D:\devel\dscoutput\temp\WinMerge-2.14.0-Setup.exe";
                Invoke-WebRequest -Uri $Uri -OutFile $OutFile;
                Unblock-File -Path $OutFile;
                };
            TestScript = { Test-Path -Path "D:\devel\dscoutput\temp\WinMerge-2.14.0-Setup.exe"; }
        } 
        
        
        Script Download_SlikSvn {
            GetScript = { @{ Result = (Test-Path -Path "D:\devel\dscoutput\temp\Slik-Subversion-1.8.11-x64.msi"); } };
            SetScript = {
                $Uri = 'https://sliksvn.com/pub/Slik-Subversion-1.8.11-x64.msi';
                $OutFile = "D:\devel\dscoutput\temp\Slik-Subversion-1.8.11-x64.msi";
                Invoke-WebRequest -Uri $Uri -OutFile $OutFile;
                Unblock-File -Path $OutFile;
                };
            TestScript = { Test-Path -Path "D:\devel\dscoutput\temp\Slik-Subversion-1.8.11-x64.msi"; }
        } 
        
               
    }
}


#

configuration ManagementTools2
{
    param(
	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[Object[]]$ServerTools,


	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[Object[]]$Products
    )

    foreach($server in $ServerTools)
    {
        Node $server.name
        {
           
            foreach($product in $server.products.product)
            {
                 $productDefinition = $Products | ? {$_.uniqueKey -eq $product.uniqueKey}

                 if ($productDefinition)
                 {

                    Package "Install_$($productDefinition.uniqueKey)" {
                        DependsOn = "[Script]Download_$($productDefinition.uniqueKey)"
                        Ensure = 'Present'
                        Name = $productDefinition.name
                        Path = $productDefinition.localPath
                        ProductId = $productDefinition.productId
                        Arguments = $productDefinition.installArguments             
                    }



                    Script "Download_$($productDefinition.uniqueKey)" {
                        GetScript = [scriptblock]::create("@{ Result = (Test-Path -Path '$($productDefinition.localPath)'); }");
                        SetScript = [scriptblock]::create("`$Uri = '$($productDefinition.remoteUri)';`$OutFile = '$($productDefinition.localPath)';Invoke-WebRequest -Uri `$Uri -OutFile `$OutFile;Unblock-File -Path `$OutFile;");
                        TestScript = [scriptblock]::create("Test-Path -Path '$($productDefinition.localPath)';")
                    } 
                }
                else
                {
                    write-warning "No product definition found for $($productDefinition.name)" 
                }
            }

            $ProductDefinition = new-Object PSObject
            ApplyArchive -ProductDefinition $ProductDefinition
        }           
    }	
	
}

Configuration ApplyArchive
{
    param(
	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[Object]$ProductDefinition
    )

    Archive DSCWave {
        DependsOn = '[Script]DSCWave'
        Ensure = 'Present'
        #Path = "$env:windirtempDSC Resource Kit Wave 6 08212014.zip";
        Path = "D:\devel\dscoutput\temp\DSC-Resource-Kit-All.zip"
        #Destination = "$env:ProgramFilesWindowsPowerShellModules";
        Destination = "D:\devel\MESF\Main\Powershell\CustomPowershellModules"
    }
    

}
